package com.xayy.health.mgt.service.impl;

import cn.kawins.base.result.CheckResult;
import cn.kawins.mybatis.base.BaseServiceImpl;
import com.xayy.health.mgt.model.HealthAssessRecord;
import com.xayy.health.mgt.service.HealthAssessRecordService;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.Date;
import java.util.Objects;

/**
 * @author Nie
 * @version V1.0
 * @date 2023/4/11 11:15
 */
@Service
public class HealthAssessRecordServiceImpl extends BaseServiceImpl<HealthAssessRecord>
        implements HealthAssessRecordService {

    /**
     * 查询健康评估记录信息
     *
     * @param startTime  开始时间
     * @param endTime    结束时间
     * @param pageStart  起始页
     * @param pageLength 页数
     * @return 结果信息
     */
    @Override
    public CheckResult<?> pageListInfo(Date startTime, Date endTime, Integer pageStart, Integer pageLength) {
        Example example = new Example(HealthAssessRecord.class);
        Example.Criteria criteria = example.createCriteria();
        if (Objects.nonNull(startTime)) {
            criteria.andGreaterThanOrEqualTo("fractionTime", startTime);
        }
        if (Objects.nonNull(endTime)) {
            criteria.andLessThanOrEqualTo("fractionTime", endTime);
        }
        example.orderBy("fractionTime").desc();
        return CheckResult.success(pageList(example, pageStart, pageLength));
    }
}
